home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / misc / soa-easy.shar / make-SOA < prev    next >
Encoding:
Text File  |  1996-10-25  |  4.0 KB  |  201 lines

  1. #!/usr/local/bin/perl
  2. # make-SOA -    Generate a DNS SOA record for a domain
  3. #
  4. # $Id: soa-easy.shar,v 8.2 1996/10/25 17:08:00 vixie Exp $
  5. # $Source: /proj/src/isc/cvs-1/bind/contrib/misc/soa-easy.shar,v $
  6. #
  7. # SYNOPSIS
  8. #    make-SOA -o SOA-file domain-file
  9.  
  10.  
  11. #
  12. # Values for the SOA record.  See RFC1035 for info.
  13. #
  14.  
  15. #
  16. # The <domain-name> of the name server that was the original or
  17. # primary source of data for this zone.
  18. $SOA_MNAME =    'ns.example.org.au.';
  19.  
  20. #
  21. # A <domain-name> which specifies the mailbox of the person
  22. # responsible for this zone
  23. $SOA_RNAME =    'hostmaster.example.org.au.';
  24.  
  25. #
  26. # A 32 bit time interval (in seconds) before the zone should be
  27. # refreshed
  28. $SOA_REFRESH =    10800;        # 3 hours
  29.  
  30. #
  31. # A 32 bit time interval that should elapse before a failed refresh
  32. # should be retried
  33. $SOA_RETRY =    3600;        # 1 hour
  34.  
  35. #
  36. # A 32 bit time value that specifies the upper limit on the time
  37. # interval that can elapse before the zone is no longer authoritative.
  38. $SOA_EXPIRE =    2592000;    # 30 days
  39.  
  40. #
  41. # The unsigned 32 bit minimum time-to-live field that should be
  42. # exported with any resource record from this zone.
  43. $SOA_MINIMUM =    86400;        # 24 hours
  44.  
  45.  
  46. $prog = 'make-SOA';
  47.  
  48. $usage = 'usage: ' . $prog . ' -o SOA-file domain-file';
  49.  
  50. if (($#ARGV != 2) || ($ARGV[0] ne '-o')) {
  51.     die $usage . "\n";
  52. }
  53.  
  54. $soa_file = $ARGV[1];
  55. $domain_file = $ARGV[2];
  56.  
  57.  
  58. #
  59. # Read current serial number from SOA-file, if any
  60. #
  61. if (-f $soa_file) {
  62.     open (SOA, $soa_file) || die "$prog: can't open $soa_file: $!\n";
  63.     while (<SOA>) {
  64.     if (/; -SERIAL- \(make-SOA\)/) {
  65.         s/^\s*//;
  66.         ($old_serial, $dummy) = split;
  67.         last;
  68.     }
  69.     }
  70.     close (SOA);
  71.     if (! length ($old_serial)) {
  72.     warn "$prog: warning: can't find SERIAL in SOA-file\n";
  73.     }
  74. } else {
  75.     warn "$prog: warning: no existing SOA-file\n";
  76. }
  77.  
  78. #
  79. # Starting with the domain file, read it, obtain any RCS Id keywords,
  80. # and repeat for any $INCLUDE files
  81. #
  82.  
  83. &get_rcs ($domain_file);
  84.  
  85. #
  86. # Calculate serial number
  87. #
  88.  
  89. #print (join ("\n", "RCS ID data:", @rcs_ids, ""));
  90.  
  91. #
  92. # Discard all but the date
  93. foreach (@rcs_ids) {
  94.     s/^\s*//;
  95.     @fields = split;
  96.     $_ = $fields[2];
  97. }
  98.  
  99. @rcs_ids = sort (@rcs_ids);
  100. $most_recent = pop (@rcs_ids);
  101. $most_recent =~ s/\///g;        # Remove slashes
  102.  
  103. #
  104. # Sanity check
  105. #
  106. if (! ($most_recent =~ /^[0-9]+$/)
  107.     || ($most_recent > 99999999))
  108. {
  109.     die "$prog: generated SERIAL is too big\n";
  110. }
  111.  
  112. $serial = $most_recent * 100;
  113.  
  114. while (1) {
  115.     last if ($serial > $old_serial);
  116.     $serial++;
  117.     if ($serial >> 9999999999) {
  118.     die "$prog: generated SERIAL is too big\n";
  119.     }
  120. }
  121.  
  122. #
  123. # Backup existing SOA-file, if any
  124. #
  125. $backup_file = $soa_file . '.backup';
  126.  
  127. unlink ($backup_file);
  128. rename ($soa_file, $backup_file);
  129.  
  130.  
  131. #
  132. # Write new SOA-file
  133. #
  134. open (SOA, '>' . $soa_file) || die "$prog: can't open $soa_file: $!\n";
  135. print (SOA
  136. "; $soa_file -    SOA record for inclusion in $domain_file
  137. ;
  138. ; NOTE:  This file is generated by $prog -- DO NOT EDIT
  139. ;
  140. @  IN  SOA  $SOA_MNAME $SOA_RNAME (
  141.             $serial    ; -SERIAL- (make-SOA)
  142.             $SOA_REFRESH    ; REFRESH
  143.             $SOA_RETRY    ; RETRY
  144.             $SOA_EXPIRE    ; EXPIRE
  145.             $SOA_MINIMUM    ; MINIMUM
  146.             )
  147. ") || die "$prog: can't write to $soa_file: $!\n";
  148. close (SOA) || die "$prog: can't close $soa_file: $!\n";
  149.  
  150. #
  151. # Remove backup SOA-file
  152. #
  153. unlink ($backup_file);
  154.  
  155. #
  156. # EXIT
  157. #
  158. exit (0);
  159.  
  160.  
  161. ###############################################################
  162. # get_rcs -    Obtain RCS Id keywords, handling $INCLUDE files
  163. #
  164. # GLOBALS
  165. #    @rcs_ids
  166. #
  167. sub get_rcs {
  168.     local ($file_name) = shift (@_);
  169.  
  170.     local ($_);
  171.     local (@includes);
  172.     local (@parts);
  173.  
  174.     open (FILE, $file_name) || die "$prog: can't open $file_name: $!\n";
  175.  
  176.     while (<FILE>) {
  177.     #
  178.     # The [I] is to prevent RCS thinking it is an RCS keyword
  179.     #
  180.     if (/\$[I]d:\s.*$/) {
  181.         $_ = substr ($_, index ($_, '$Id:') + 4);
  182.         s/\$.*\n*$//;
  183.         push (@rcs_ids, $_);
  184.     }
  185.     s/;.*$//;
  186.     if (/\$INCLUDE\s/) {
  187.         @parts = split; $_ = $parts[1];
  188.         if (length ($_) && (! /\.SOA$/)) {
  189.         push (@includes, $parts[1]); }
  190.     }
  191.     }
  192.     close (FILE);
  193.  
  194.     #
  195.     # Recurse on $INCLUDE-ed files
  196.     #
  197.     foreach (@includes) {
  198.     &get_rcs ($_);
  199.     }
  200. }
  201.